<?php 
/* 
PayKred payment module. This file is used to get status of
this module.

Copyright (c) 2010 Ingvar Harjaks <ingvarharjaks@gmail.com>
All costs of this development were covered by open source fiendy
company BrightSide OÜ <www.brightside.ee>

PayKred is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PayKred is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PayKred. If not, see <http://www.gnu.org/licenses/>.
*/

class ModelPaymentPayKred extends Model {

  public function getMethod($address) {
    $this->load->language('payment/paykred');

    if ($this->config->get('paykred_status')) {
      $sql = 'SELECT * FROM %szone_to_geo_zone WHERE 
geo_zone_id="%s" AND country_id="%s" AND (zone_id=%s OR zone_id=0)';
      $p = array();
      $p[] = DB_PREFIX;
      $p[] = (int)$this->config->get('paykred_geo_zone_id');
      $p[] = (int)$address['country_id'];
      $p[] = (int)$address['zone_id'];
      
      $query = $this->db->query(vsprintf($sql, $p));
      
      if (!$this->config->get('paykred_geo_zone_id')) {
	$status = true;
      } elseif ($query->num_rows) {
	$status = true;
      } else {
	$status = false;
      }
    } else {
      $status = false;
    }

    $method_data = array();
    if ($status) {  
      $method_data = array( 
			   'code'         => 'paykred',
			   'title'      => $this->language->get('text_title'),
			   'sort_order' => $this->config->get('paykred_sort_order')
			    );
    }
    
    return $method_data;
  }
}